#!/usr/bin/python

import xmlrpclib

srv = xmlrpclib.Server("http://127.0.0.1:32678");

feeds = srv.feedreader.getfeeds();

print "FEEDS";
for feed in feeds:
	print str(feed["FeedID"]) + ":" + feed["Name"] + " (" + str(feed["DateTime"]) + ")";
	print "    " + feed["Url"];

print "ADDTAG returned = " + str(srv.feedreader.addtag("Pingochoxxx"));
print "ADDTAG returned = " + str(srv.feedreader.addtag("Mamertoxxx"));

tags = srv.feedreader.gettags();

print "";
print "TAGS";
for tag in tags:
	print str(tag["TagID"]) + ":" + tag["Name"];

print "";
print "GetFeedByNumber";
news = srv.feedreader.getfeedbynumber(1,0,10);
#for new in news:
#	print str(new["NewsID"]) + ":" + new["Title"] + " (" + str(new["DateTime"]);
decorated = [(99999999999999999999 - n["DateTime"],n) for n in news];
decorated.sort();
for datetime, new in decorated:
	print str(new["NewsID"]) + ":" + new["Title"] + " (" + str(new["DateTime"]);


print "";
print "GetNewsByNumber";
news = srv.feedreader.getnewsbynumber(10);
print str(news["NewsID"]) + ":" + news["Title"] + "(" + news["Author"] + ")";
print "    " + news["Url"];
tmp = "";
for i in news["Tags"]:
	tmp += str(i) + " ";
print "    Tags: " + tmp;
print "    " + news["Description"]

print "";
print "GET NEWS";
news = srv.feedreader.getnews(50,5);
for new in news:
	print str(new["NewsID"]) + ":" + new["Title"];

print "";
print "ADDFEED returned " + str(srv.feedreader.addfeed("http://rss.slashdot.org/Slashdot/slashdot","http://rss.slashdot.org/Slashdot/slashdot"));

print "";
print "DELFEED returned " + str(srv.feedreader.delfeed(3));
print "";
print "DELFEED returned " + str(srv.feedreader.delfeed(2));
print "";
print "DELFEED returned " + str(srv.feedreader.delfeed(5));

tags = [10,20,30];
print "";
print "ASSIGNTAG returned " + str(srv.feedreader.assigntags(1,100,tags));

print "";
print "REMOVETAG returned " + str(srv.feedreader.removetags(1,200,tags));
